﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Pages_NhapThongTinThanhToan : System.Web.UI.UserControl
{
    BLLSanPham bllSanPham;
    BLLHoaDon bllHoaDon;

    protected void Page_Load(object sender, EventArgs e)
    {
        bllSanPham = new BLLSanPham();
        bllHoaDon = new BLLHoaDon();
        if (!IsPostBack)
        {
            bllSanPham = new BLLSanPham();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("history.go(-1)");
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {

         int idHoadon=   bllSanPham.insertHoaDon(DateTime.Now.Date, DateTime.Parse(RequiredDate.Text), txtNguoiNhan.Text, txtAddress.Text, HttpContext.Current.Session["User"].ToString());
     Response.Write(idHoadon.ToString());

         DataTable dt = (DataTable)HttpContext.Current.Session["GioHang"];
         if (dt != null)
         {
             foreach (DataRow dr in dt.Rows)
             {
                 bllHoaDon.insert(idHoadon, dr["Masp"].ToString(), (int)dr["SoLuong"]);
             }
            // Response.Write("<script>alert('Bạn đã thực hiện thành công') </script>");
         }
         ((DataTable)HttpContext.Current.Session["GioHang"]).Rows.Clear();
      HttpContext.Current.Session["Gia"] = 0;
      Response.Redirect("ShowFlower.aspx");      
        }
}